ABC256 D - Union of Interval


WA
n = int(input())
lr = [list(map(int, input().split())) for _ in range(n)]
# minmax
lr.sort()
tmpl = lr[0][0]
tmpr = lr[0][1]
for i in range(1, n):
if (lr[i][0] <= tmpr):
continue
else:
print(tmpl, lr[i][1])
tmpl = lr[i][0]
tmpr = lr[i][1]



n = int(input())
lr = [list(map(int, input().split())) for _ in range(n)]
lr.sort()
#
nowL = lr[0][0]
#
nowR = lr[0][1]
for i in range(1,n):
# (i)
nextL = lr[i][0]
# (i)
nextR = lr[i][1]
# <
if nowR < nextL:
# [nowL,nowR)
print(nowL, nowR)
#
nowL = nextL
nowR = nextR
# ()
else:
# <
if nowR < nextR:
# ()
nowR = nextR
#
print(nowL, nowR)




import bisect
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
print(xy)
# 10 20
# 20 30
# 40 50
# 10-20
# 20-30 40-50
# 10 40
# 30 60
# 20 50
# 10-------40
# 30-------60
# 20-------50
#
# l, r
#
l, r = [], []
for x, y in xy:
i = bisect.bisect_left(l, x)
j = bisect.bisect_left(r, y)